<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function fn(){
            return new Promise((resolve,reject) =>{
                setTimeout(() =>{
                    // return Math.random()>0.5? true:false;
                    // 方法1
                    // resolve(Math.random()>0.5? true:false);
                    // reject();
                    // 方法2
                    // return Math.random()>0.5? resolve(Math.random()):reject(Math.random());
                    // 方法3
                    return Math.random()>0.5? resolve(true):reject(false);
                    
                },1000)
            })
        }

        fn().then((result) =>{
            console.log(result);
        },(error) =>{
            console.log(error);
        })
    </script>
</body>
</html>